<?

include_once 'library/smarty/src/Smarty.class.php';

class Smutty_Template extends Smarty {

	function Smutty_Template() {

		$this->compile_dir = 'application/cache';
		$this->template_dir = 'application/views/';
		$this->plugins_dir[] = 'library/smarty/plugins/'; // smutty plugins
		$this->plugins_dir[] = 'application/plugins/'; // app plugins
		$this->autoload_filters = array(
			'pre' => array( 'allow_assoc_attrs' )
		);

		$session = Smutty_Session::getInstance();

		// create the smutty variable
		$smutty = new stdclass();
		$smutty->session = $session;
		$smutty->user = $session->user;
		$smutty->baseUrl = Smutty_Utils::getBaseUrl();
		$this->assign( 'smutty', $smutty );

	}

	function display( $file ) {

		$router = Smutty_Router::getInstance();

		// try to use controller shortcut for filenames, if it
		// fails then fall back on the filename
		$path = strtolower($router->getControllerName()) . "/$file";
		if ( !file_exists("$this->template_dir$path") )
			$path = $file;

		parent::display( $path );

	}

}

?>